Skip to content

Conversation

@brandonkachen
Copy link
Collaborator

@brandonkachen brandonkachen commented Oct 9, 2024

https://www.tella.tv/video/referral-program-explained-7qdh

important: when we deploy, make sure to change APP_URL to NEXT_PUBLIC_APP_URL in our environment variables!

Brandon Chen added 25 commits October 8, 2024 21:30
This commit introduces a new knowledge file for database schema design
principles. It covers general guidelines for schema simplicity and
efficiency, as well as specific recommendations for user and referral
table designs. Key points include:

- Reusing existing fields when possible
- Using composite primary keys where appropriate
- Utilizing the 'quota' field for multiple purposes
- Efficient design for referral systems

These principles aim to improve database performance and maintainability.
This commit outlines the database schema changes and implementation
steps for the new referral feature. It includes:

- Updates to the user table
- Creation of a new referral table
- Detailed implementation steps covering database, API, UI, and testing
- Guidelines for using existing fields and efficient schema design

The plan provides a comprehensive roadmap for developing the referral
system, ensuring consistency and efficiency across the application.
This commit introduces a referral system to the application:

- Add 'referral_code' field to user table
- Create new 'referral' table to track referrals
- Update schema.ts with new fields and table definitions

The referral system will allow users to invite others and track the
status of their referrals. This lays the groundwork for future
features like referral bonuses or rewards.
This commit introduces a referral system with the following changes:
- Create 'referral' table to track referrals between users
- Add 'referral_code' column to 'user' table
- Implement 'ReferralStatus' enum for tracking referral status
- Update schema and types to support new referral functionality

These changes lay the groundwork for implementing user referrals
and tracking their status within the application.
This commit introduces a new referrals page where users can view and
manage their referral code and referrals. It also adds a link to the
referrals page in the navbar for authenticated users.

Key changes:
- Create new ReferralsPage component with referral code and list
- Add referrals link to navbar for logged-in users
- Implement basic UI for displaying referral information
This commit introduces a new API route (/api/referrals) to retrieve
referral information for authenticated users. The route fetches the
user's referral code and a list of their referrals from the database.

The implementation includes:
- Authentication check using NextAuth
- Database queries to fetch referral code and referrals
- Error handling for unauthorized access and server errors

This feature supports the referral system functionality in the web app.
This commit introduces TanStack Query for efficient data fetching and
state management in the referrals feature. It includes:

- Adding @tanstack/react-query as a dependency
- Updating the knowledge.md file with TanStack Query usage guidelines
- Refactoring the referrals API route for optimized data retrieval
- Implementing TanStack Query in the ReferralsPage component
- Updating the referrals UI to display fetched data correctly

These changes improve performance, error handling, and code
maintainability for the referrals feature.
- Introduce ReferralData type for improved type safety
- Optimize referral data processing in API route
- Implement React Query for efficient data fetching and caching
- Enhance error handling and loading states in UI
- Extract copyReferralCode function for reusability
- Update UI to use new data structure and loading states
This commit adds React Query setup to the root layout and updates
the knowledge base documentation with instructions on how to
properly initialize React Query in the application. These changes
enable the use of useQuery hooks throughout the app for efficient
data fetching and state management.
This commit moves the QueryClientProvider logic into a separate
component. It improves code organization and allows for better state
management of the QueryClient instance. The new QueryProvider
component is now used in the root layout, simplifying the main
layout file and enhancing reusability.
This commit introduces a new Skeleton component to enhance the user
experience during loading states. The component uses animation and
styling to provide a visual placeholder while content is being fetched
or processed.

The Skeleton component is flexible and can be customized through
className props, allowing for easy integration across different parts
of the application.
- Add loading states using Skeleton components
- Refresh usage on 100% warning in CLI
- Update pricing URL to use environment variable
- Reset warning percentage on plan change
- Update knowledge.md with UI component guidelines
- Refactor referrals page for better readability
- Replace hardcoded support email with environment variable
- Remove commented code in referrals page
- Improve error handling in onboarding process

These changes enhance maintainability and code cleanliness.
This commit adds functionality for users to apply referral codes:
- Create POST endpoint in /api/referrals to handle code submission
- Add input field and apply button on referrals page
- Implement client-side mutation for applying referral codes
- Display success/error messages using toast notifications
- Refetch referral data after successful code application

These changes enhance the referral system by allowing users to
enter and benefit from referral codes, completing the referral loop.
- Change key prop to use referral.id for uniqueness
- Display referral name or email instead of referred_id
- Improve readability and user experience in referrals list
This commit updates the referral system implementation to:
- Enhance database schema documentation
- Optimize API route for fetching referral data using Drizzle ORM
- Update frontend to display referred user information correctly
- Improve code organization and readability

These changes streamline the referral system, making it more
efficient and easier to maintain.
This commit updates the GET handler for the referrals API route to
improve data fetching efficiency and accuracy. Key changes include:

- Replace user query with direct referral query
- Filter for completed referrals only
- Adjust data structure to match new query results
- Enhance error handling for missing user ID

These changes aim to optimize performance and ensure only relevant,
completed referrals are returned to the client.
This commit updates the referral feature implementation:
- Revise database schema documentation
- Optimize referral data retrieval in API route
- Update referrals page to display improved data structure
- Enhance type definitions for better code clarity
- Streamline API response format for frontend consumption

These changes improve performance and maintainability of the
referral system while providing a clearer data structure for
the frontend to work with.
This commit improves the referral system by adding detailed security
measures and implementation guidelines. Key changes include:

- Prevent self-referrals to avoid system abuse
- Limit referral code usage to 5 times for better distribution
- Implement rate limiting for code generation to prevent spam
- Add implementation tips for middleware, database operations, and
  concurrent request handling

These enhancements aim to create a more robust and secure referral
system, reducing potential exploitation while maintaining usability.
- Implement security measures in GET method of referrals API
- Add referral count limit and self-referral check
- Update frontend to display referrals and handle errors
- Improve data structure for referral information
- Refactor code for better readability and maintainability
- Fix referral queries in API route
- Enhance referrals page UI with conditional rendering
- Display referrer information when available
- Adjust footer layout and wording
- Update input handling for referral code application
The updated plan includes:
- Reorganized sections for better flow
- Added UI components section
- Moved user quota update to API routes
- Removed redundant backend logic section
- Consolidated security measures under API routes
- Refined implementation tips for API routes

These changes provide a more comprehensive and organized
approach to implementing the referral system.
@brandonkachen brandonkachen requested a review from jahooma October 9, 2024 10:03
@ellipsis-dev
Copy link

ellipsis-dev bot commented Oct 9, 2024

Your free trial has expired. To keep using Ellipsis, sign up at https://app.ellipsis.dev for $20/seat/month or reach us at help@ellipsis.dev

@@ -0,0 +1,88 @@
# Referral Feature Implementation Plan
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will prob delete this before merging

Brandon Chen added 2 commits October 9, 2024 05:07
Update environment variable usage across the project
Enhance referral system with credit tracking
Improve onboarding and redeem page functionality
Brandon Chen added 5 commits October 10, 2024 16:23
- Add logout command to CLI
- Implement referral code redemption for logged-in users
- Refactor login process and referral code handling
- Update onboarding page to use new referral code redemption
- Simplify referrals page and footer component
@brandonkachen
Copy link
Collaborator Author

brandonkachen commented Oct 11, 2024

Amazing. This is pretty quick turnaround for a complex feature.

Some notes:

  • I could refer myself
  • It's weird that it involves logging in when I'm already logged in, but maybe not that bad
  • Got an error when entering the referral code again. Ideally it would say I already referred someone
  • Main problem for me is that we need people to discover referrals from within manicode. I would add a section to explain referrals in "help", but probably also print your code where it says your name on startup.

all fixed now!

Brandon Chen added 23 commits October 11, 2024 01:16
This commit enhances the referral system by adding a check for
self-referrals. It modifies the API to return whether the referral
code belongs to the current user and updates the UI to display a
warning message in such cases. This prevents users from accidentally
trying to redeem their own referral codes and improves the overall
user experience of the referral system.
This commit simplifies the usage limit message by removing the
specific upgrade instructions. It keeps the core message about
reaching the monthly limit without directing users to a particular
action, allowing for more flexibility in how this information is
presented or handled in different contexts.
This commit enhances the usage warning feature by incorporating a
referral system. It adds a referral link to the usage response for
eligible users, displays this link in the CLI usage warnings, and
updates the knowledge base to reflect these changes. The goal is to
encourage user growth by promoting referrals when users approach
their usage limits.
This commit centralizes the referral link generation logic by:

1. Creating a shared function  in common/src/util
2. Updating the backend websocket handler to use this function
3. Modifying the web API to utilize the shared function
4. Updating the knowledge base with best practices for code organization

These changes improve code reusability and maintainability across the
project, adhering to the DRY principle and promoting consistent
implementation of referral functionality.
This commit introduces several changes to the referral system:

- Implement a new  function to centralize referral
  eligibility logic
- Move referral link generation to the backend for better security
- Update frontend to handle referral limits and display appropriate
  messages
- Improve code organization by applying Single Responsibility Principle
- Enhance error handling and type safety in referral-related functions
- Update documentation with new development guidelines

These changes aim to improve maintainability, security, and user
experience of the referral system.
- Implement consistent referral limit checks
- Use hasMaxedReferrals function for limit enforcement
- Update GET and POST handlers in referrals route
- Add detailed referral system documentation
- Remove redundant code and improve error handling
This commit refactors the referral system to improve code organization
and enhance user experience. Key changes include:

- Move server-specific referral logic to a new file
- Update referral limit checks and error messages
- Improve usage warning display in the npm client
- Centralize referral link generation
- Update API endpoints to use new referral functions
- Enhance referral page to use consistent link generation

These changes aim to make the referral system more robust and
user-friendly while improving code maintainability.
This commit centralizes the MAX_REFERRALS constant in constants.ts and
updates its imports across the codebase. It improves code organization
and maintainability by keeping all constants in a single location.

The changes include:
- Adding MAX_REFERRALS to constants.ts
- Updating imports in referral.ts and route.ts
- Removing duplicate constant definition in referral.ts

This refactoring ensures consistency and reduces the risk of
discrepancies in referral-related logic across the application.
This commit introduces a new knowledge.md file in the common directory,
documenting key aspects of the Manicode project structure, constants,
and referral system. It also corrects an import path in the referral
utility file to use a relative path for better module resolution.

These changes improve project documentation and code organization,
making it easier for developers to understand and maintain the codebase.
This commit adds information about important constants and the
referral system to the knowledge.md file. It includes details on:

- Location of constants in common/src/constants.ts
- Key constants like MAX_REFERRALS and CREDITS_REFERRAL_BONUS
- Overview of the referral system implementation
- Files involved in the referral system

This update helps developers understand the project structure and
key components related to constants and the referral system.
This commit removes the outdated constants section from the
knowledge.md file. The information about important constants and
their definitions has been moved to a more appropriate location
in the codebase, improving overall documentation structure and
maintainability.
This commit improves the referral system by:
- Optimizing the database query in hasMaxedReferrals function
- Updating referral system documentation in knowledge.md

It also enhances usage limit handling in the CLI by:
- Moving the usage limit warning from CLI to Client class
- Ensuring proper control flow when usage limit is reached

These changes improve code organization and user experience.
This commit addresses two main changes:

1. Corrects the referral query in referral.ts by properly joining
   the user table and uncommenting the where clause.

2. Adds a usage check in the CLI's printInitialPrompt method to
   fetch and display user usage information before the prompt.

These changes improve the accuracy of referral tracking and
enhance the user experience by providing usage information
upfront.
This commit addresses two issues:

1. In the backend, the 'user-input' action subscription is updated to
   properly wrap the callback function with protec.run().

2. In the npm-app client, the usage response output is modified to
   include a newline character before printing, improving readability
   in the console.

These changes enhance the reliability of websocket actions and improve
the user experience when displaying usage information.
@brandonkachen brandonkachen merged commit bcb4331 into main Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants